home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / Hydra11s.lha / HBBS / Source / Doors_System / Announce / Main.C < prev    next >
C/C++ Source or Header  |  1996-10-31  |  4KB  |  207 lines

  1. /* **** HBBS Door Code****************************************************** */
  2.  
  3. /*
  4.   DoorName
  5.   ========
  6.  
  7.     what the door does
  8.  
  9.   Version
  10.   =======
  11.  
  12.     x.xx, release xx, dd/mm/yyyy
  13.  
  14.   Options
  15.   =======
  16.  
  17.     N_ND->ActiveDoor->SystemOptions
  18.     -------------------------------
  19.  
  20.  
  21.  
  22.     Command Line Arguments
  23.     ----------------------
  24.  
  25.     2  <option>
  26.  
  27.     3  ...
  28.  
  29.     4  .
  30.  
  31.   ToDo
  32.   ====
  33.  
  34.     what you still have to do
  35.  
  36.  
  37.  
  38. */
  39.  
  40. /* **** Includes *********************************************************** */
  41.  
  42. #include <exec/types.h>
  43. #include <exec/memory.h>
  44. #include <dos/dos.h>
  45. #include <clib/exec_protos.h>
  46. #include <clib/dos_protos.h>
  47. #include <clib/alib_protos.h>
  48.  
  49. #include <stdlib.h>
  50. #include <string.h>
  51. #include <stdio.h>
  52. #include <ctype.h>
  53. #include <time.h>
  54.  
  55. #include <HBBS/ANSI_Codes.h>
  56. #include <HBBS/Defines.h>
  57. #include <HBBS/Access.h>
  58. #include <HBBS/types.h>
  59. #include <HBBS/structures.h>
  60. #include <HBBS/hbbscommon_protos.h>
  61. #include <HBBS/hbbscommon_pragmas.h>
  62. #include <HBBS/Hbbsnode_protos.h>
  63. #include <HBBS/Hbbsnode_pragmas.h>
  64. #include <HBBS/release.h>
  65. char *versionstr="$VER: Announce "RELEASE_STR;
  66.  
  67. /* **** Variables ********************************************************** */
  68.  
  69.  
  70. struct Library *HBBSCommonBase  = NULL;
  71. struct Library *HBBSNodeBase    = NULL;
  72.  
  73. struct BBSGlobalData *BBSGlobal = NULL;
  74. struct NodeData *N_ND           = NULL;
  75. int    N_NodeNum                = -1;
  76. char   outstr[1024];
  77.  
  78. long __stack=16*1024; // increse this in 4k incrments if you suffer from
  79.                       // random/suprious crashings after or during the running
  80.                       // of your door.
  81.  
  82. int    gargc;         // these are just copies of main()'s argc and argv..
  83. char   **gargv;
  84.  
  85. /* **** Functions ********************************************************** */
  86.  
  87.  
  88. #ifdef __SASC
  89. int CXBRK(void) { return(0); }
  90. int _CXBRK(void) { return(0); }
  91. void chkabort(void) {}
  92. #endif
  93.  
  94. static VOID cleanup(ULONG num)
  95. {
  96.   if (HBBSNodeBase)
  97.   {
  98.     HBBS_CleanUpDoor();
  99.     CloseLibrary (HBBSNodeBase);
  100.   }
  101.  
  102.   if (HBBSCommonBase)
  103.   {
  104.     HBBS_CleanUpCommon();
  105.     CloseLibrary (HBBSCommonBase);
  106.   }
  107.  
  108.   if (num) printf("Door Error = %d\n",num);
  109.  
  110.   exit(0);
  111. }
  112.  
  113. static VOID init(char *name)
  114. {
  115.   if(!(HBBSCommonBase = OpenLibrary("HBBSCommon.library",0)))
  116.   {
  117.     cleanup(1);
  118.   }
  119.  
  120.   if (!(HBBS_InitCommon()))
  121.   {
  122.     cleanup(2);
  123.   }
  124.  
  125.   if(!(HBBSNodeBase = OpenLibrary("HBBSNode.library",0)))
  126.   {
  127.     cleanup(3);
  128.   }
  129.  
  130.   if (!(HBBS_InitDoor(N_NodeNum,name)))
  131.   {
  132.     cleanup(4);
  133.   }
  134.   SetProgramName(name);
  135. }
  136.  
  137. /* **** DoorMain *********************************************************** */
  138.  
  139. void DoorMain( void )
  140. {
  141.   LONG loop;
  142.   struct NodeData *nd;
  143.   BOOL Sent;
  144.   outstr[0]=0;
  145.  
  146.   if (gargc==3)
  147.   {
  148.     DOOR_SysopText("Announcement: ");
  149.     for (loop=0;loop<BBSGlobal->BBSNodes;loop++)
  150.     {
  151.       Sent=FALSE;
  152.       if (loop!=N_ND->NodeNum) // don't send to our own node!
  153.       {
  154.         if (nd=HBBS_NodeDataPtr(loop))
  155.         {
  156.           sprintf(outstr,"%s just logged %s node %ld",N_ND->User.CallData.Handle,gargv[2],N_ND->NodeNum);
  157.  
  158.           // if user has logged on the uer might want to say hi via an olm
  159.           // but there's no point letting the user reply to an olm that says
  160.           // the user has just logged off! :-)
  161.           if (HBBS_SendOLM((stricmp(gargv[2],"ON")==0) ? N_ND->NodeNum+1 : 0,"Announce",loop,outstr,1)) // set pri just above normal OLM's
  162.           {
  163.             Sent=TRUE;
  164.             sprintf(outstr,"%s%ld "ANSI_FG_BLUE"- "ANSI_FG_YELLOW"YES"ANSI_FG_WHITE,loop >0 ? ", " : "",loop);
  165.             DOOR_SysopText(outstr);
  166.           }
  167.         }
  168.       }
  169.       if (!Sent)
  170.       {
  171.         sprintf(outstr,"%s%ld "ANSI_FG_BLUE"- "ANSI_FG_GREEN"NO"ANSI_FG_WHITE,loop >0 ? ", " : "",loop);
  172.         DOOR_SysopText(outstr);
  173.       }
  174.     }
  175.     DOOR_SysopText("\r\n");
  176.   }
  177.   else
  178.   {
  179.     DOOR_WriteText("Invalid Parameters! usage: Announce [on|off]\r\n");
  180.   }
  181. }
  182.  
  183.  
  184. int main(int argc,char **argv)
  185. {
  186.   gargc=argc;
  187.   gargv=argv;
  188.  
  189.   if (sscanf(argv[1],"%d",&N_NodeNum)==0)
  190.   {
  191.     printf("Invalid/No Paramaters for door!\n");
  192.     exit (20);
  193.   }
  194.   init("Writing OLM");
  195.  
  196.   if (BBSGlobal=HBBS_GimmeBBS())
  197.   {
  198.     if (N_ND=HBBS_NodeDataPtr(N_NodeNum)) // this should not fail in normal circumstances..
  199.     {
  200.       DoorMain();
  201.     }
  202.   }
  203.   cleanup(0);
  204. }
  205.  
  206. /* **** End Of File ******************************************************** */
  207.